package com.neusoft.neuiotms.dcom.model;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;

import org.hibernate.validator.constraints.Length;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.neusoft.bizcore.web.jpa.model.AbstractAuditModel;
import com.neusoft.bizcore.web.jpa.model.Comment;
import com.neusoft.neuiotms.dcom.model.enums.InspectionTaskStatus;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
@Table(name = "neuiot_inspection_task")
@org.hibernate.annotations.Table(appliesTo = "neuiot_inspection_task", comment = "巡检任务表")
public class InspectionTask extends AbstractAuditModel {

    private static final long serialVersionUID = -1903441722461844329L;

    @ManyToOne
    private InspectionRule inspectionRule;

    @NotBlank(message = "任务名称")
    @Length(max = 255, message = "任务名称不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '任务名称'")
    private String name;

    @Length(max = 255, message = "领取人编码不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NOT NULL COMMENT '领取人编码'")
    private String claimCode;

    @Length(max = 255, message = "领取人名称不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '领取人名称'")
    private String claimName;

    @Length(max = 255, message = "巡检人编码不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NOT NULL COMMENT '巡检人编码'")
    private String usercode;

    @Length(max = 255, message = "巡检人名称不能超过{max}位")
    @Column(length = 255, nullable = true)
    @Comment("varchar(255) NULL COMMENT '巡检人名称'")
    private String username;

    @Enumerated(EnumType.STRING)
    @Column(length = 32, nullable = false)
    @Comment("varchar(32) NOT NULL COMMENT '任务状态'")
    private InspectionTaskStatus status = InspectionTaskStatus.notStarted;

    @Column(length = 32, nullable = true)
    @Comment("int(32) NULL COMMENT '正常项目数'")
    private Integer normal;

    @Column(length = 32, nullable = true)
    @Comment("int(32) NULL COMMENT '告警项目数'")
    private Integer alarm;

    @Column(length = 32, nullable = true)
    @Comment("int(15) NULL COMMENT '预警项目数'")
    private Integer earlyWarning;

    @Column(length = 15, nullable = true)
    @Comment("int(15) NULL COMMENT '未巡检项目数'")
    private Integer uninspected;

    @Column(nullable = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Comment("datetime NOT NULL COMMENT '计划任务开始时间'")
    private Date startTaskTime;

    @Column(nullable = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Comment("datetime NOT NULL COMMENT '计划任务结束时间'")
    private Date endTaskTime;

    @Column(nullable = true)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Comment("datetime NULL DEFAULT NULL COMMENT '任务领取时间'")
    private Date getTaskTime;

    @Column(nullable = true)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Comment("datetime NULL DEFAULT NULL COMMENT '实际完成时间'")
    private Date finishTaskTime;

    @Length(max = 1023, message = "备注不能超过{max}位")
    @Column(length = 1023, nullable = true)
    @Comment("varchar(1023) NULL COMMENT '备注'")
    private String note;

    @OneToMany(mappedBy = "InspectionTask", cascade = CascadeType.ALL)
    private List<InspectionTaskProject> inspectionTaskProject;

}
